package com.cg.design.graphicdesignpattern.builder;

/**
 * Builder类的子类，使用纯文本编写文档，并以String返回结果
 *
 * @program: LeetCode->TextBuilder
 * @description: Builder类的子类，使用纯文本编写文档，并以String返回结果
 * @author: cg
 * @create: 2022-03-20 21:04
 **/
public class TextBuilder extends Builder {

    /**
     * 文档内容保存在buffer中
     */
    private StringBuffer buffer = new StringBuffer();

    @Override
    protected void buildTitle(String title) {
        buffer.append("==============================\n");
        buffer.append("『" + title + "』\n");
        buffer.append("\n");
    }

    @Override
    protected void buildString(String string) {
        buffer.append('■' + string + "\n");
        buffer.append("\n");
    }

    @Override
    protected void buildItems(String[] items) {
        for (int i = 0; i < items.length; i++) {
            buffer.append("   · " + items[i] + "\n");
        }
        buffer.append("\n");
    }

    @Override
    protected void buildDone() {
        buffer.append("==============================\n");
    }

    public String getResult() {
        return buffer.toString();
    }

}
